package com.shenzhen.horselive.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.flqy.baselibrary.utils.L;
import com.google.android.material.tabs.TabLayout;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.User;
import com.shenzhen.horselive.adapter.TypeDetailsAdapter;
import com.shenzhen.horselive.api.ApiFactory;
import com.shenzhen.horselive.base.AppBarActivity;
import com.shenzhen.horselive.beans.TypeDetailsBean;
import com.shenzhen.horselive.databinding.ActivityFenZhiDetailsBinding;
import com.shenzhen.horselive.network.SchedulersCompat;
import com.shenzhen.horselive.presenter.LoadingViewObserver;

/**
 * 峰值明细  或者其他明细帐户类型: 0:人民币帐户 ,1:蜂值帐户 ,2:红包股帐户 ,3:金卡帐户
 */
public class FenZhiDetailsActivity extends AppBarActivity {

    ActivityFenZhiDetailsBinding  binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityFenZhiDetailsBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setStyleDark();
        initViews();
        getAddList();
    }

    TypeDetailsAdapter adapter;
    int  type;
    private void initViews() {
        type =  getIntent().getIntExtra("type",0);
        switch (type)
        {
            case 0:
                setTitle("钱包明细");
                break;
            case 1:
                setTitle("峰值明细");
                break;
            case 2:
                setTitle("红包股明细");
                break;
        }



        adapter = new TypeDetailsAdapter(R.layout.item_details);
        binding.recyclerview.setLayoutManager(new LinearLayoutManager(this));
        binding.recyclerview.setAdapter(adapter);
        adapter.setEmptyView(R.layout.no_data_layout);
        binding.tabs.addOnTabSelectedListener(new TabLayout.BaseOnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                switch (tab.getPosition())
                {
                    case 0:
                        getAddList();
                        break;
                    case 1:
                        getDownList();
                        break;
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    private void getAddList() {
        ApiFactory.getApiService().typeDetails(User.get().getMyInfo().getToken(),getIntent().getIntExtra("type",0)+""
        ,"1,3,6"
        ).compose(SchedulersCompat.applyIoSchedulers())
                .safeSubscribe(new LoadingViewObserver<TypeDetailsBean>(this) {
                    @Override
                    protected void onNextInActive(TypeDetailsBean typeDetailsBean) {
                        if (typeDetailsBean.isSuccess()&&typeDetailsBean.getData()!=null&&typeDetailsBean.getData().getContent()!=null)
                        {
                            adapter.setNewInstance(typeDetailsBean.getData().getContent());
                        }
                    }
                });
    }


    private void getDownList() {
        ApiFactory.getApiService().typeDetails(User.get().getMyInfo().getToken(),getIntent().getIntExtra("type",0)+""
                ,"4,5"
        ).compose(SchedulersCompat.applyIoSchedulers())
                .safeSubscribe(new LoadingViewObserver<TypeDetailsBean>(this) {
                    @Override
                    protected void onNextInActive(TypeDetailsBean typeDetailsBean) {
                        if (typeDetailsBean.isSuccess()&&typeDetailsBean.getData()!=null&&typeDetailsBean.getData().getContent()!=null)
                        {
                            adapter.setNewInstance(typeDetailsBean.getData().getContent());
                        }
                    }
                });
    }
    //帐户类型: 0:人民币帐户 ,1:蜂值帐户 ,2:红包股帐户 ,3:金卡帐户
    public static void start(Context context,int  type) {
        Intent starter = new Intent(context, FenZhiDetailsActivity.class);
        starter.putExtra("type",type);
        context.startActivity(starter);
    }


}